#include <header.h>

int done = 0;
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

void thr_exit() { 
    pthread_mutex_lock(&lock);
    done = 1; 
    pthread_cond_signal(&cond); 
    pthread_mutex_unlock(&lock); 
}
void *child(void *arg) { 
    printf("child\n"); 
    thr_exit(); 
    return NULL; 
} 
void thr_join(){ 
    pthread_mutex_lock(&lock); 
    while (done == 0)
        pthread_cond_wait(&cond, &lock);
    pthread_mutex_unlock(&lock);
} 



int main(void){
    printf("parent: begin\n"); 
    pthread_t p; 
    pthread_create(&p, NULL, child, NULL); 
    thr_join(); 
    printf("parent: end\n"); 
    return 0; 
}